package com.jianshuge.app.bean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.jianshuge.app.AppException;
import org.json.JSONException;
import org.json.JSONObject;

/*** 我的资料实体类  ***/

public class MyInformation extends Entity{

	private String user_avatar;
	private String user_nickname;
	private String user_email;
	private String user_location;
	private String user_summary;
	private String user_jointime;


	private int favorite_count;
	private int followers_count;
	private int friends_count;
	private int fbl_count;
	private int cbl_count;
	private int pbl_count;
	private int vote_up_count;
	private int be_voted_count;
	
	private int login_count;
	private String last_login_time;
	
	private int gender;
	
	public int getGender() {
		return gender;
	}
	public void setGender(int gender) {
		this.gender = gender;
	}
	
	public String getJointime() {
		return user_jointime;
	}
	
	public void setJointime(String jointime) {
		this.user_jointime = jointime;
	}

	public String getSummary() {
		return user_summary;
	}
	
	public void setSummary(String summary) {
		this.user_summary = summary;
	}

	public String getEmail() {
		return user_email;
	}
	
	public void setEmail(String my_email) {
		this.user_email = my_email;
	}
	
	public String getNickName() {
		return user_nickname;
	}
	
	public void setNickName(String name) {
		this.user_nickname = name;
	}
	
	public String getUserAvatar() {
		return user_avatar;
	}
	
	public void setUserAvatar(String face) {
		this.user_avatar = face;
	}
	
	public String getLocation() {
		return user_location;
	}
	
	public void setLocation(String from) {
		this.user_location = from;
	}
	
	public int getFavoriteCount() {
		return favorite_count;
	}
	
	public void setFavoritecount(int favoritecount) {
		this.favorite_count = favoritecount;
	}
	
	public int getFriendCount() {
		return friends_count;
	}
	
	public void setFriendCount(int friendcount) {
		this.friends_count = friendcount;
	}
	
	public int getFollowerCount() {
		return followers_count;
	}
	
	public void setFollowerCount(int followerscount) {
		this.followers_count = followerscount;
	}
	
	public int getFBLCount() {
		return fbl_count;
	}
	
	public void setFBLCount(int followerscount) {
		this.fbl_count = followerscount;
	}

	public int getCBLCount() {
		return cbl_count;
	}
	
	public void setCBLCount(int cbl_count) {
		this.cbl_count = cbl_count;
	}
	
	public int getPBLCount() {
		return pbl_count;
	}
	
	public void setPBLCount(int pbl_count) {
		this.pbl_count = pbl_count;
	}
	
	public void setVoteUpCount(int vote_up_count) {
		this.vote_up_count = vote_up_count;
	}
	
	public int getVoteUpCount() {
		return vote_up_count;
	}
	
	public void setBeVotedCount(int be_voted_count) {
		this.be_voted_count = be_voted_count;
	}
	
	public int getBeVotedCount() {
		return be_voted_count;
	}
	
	public void setLoginCount(int login_count) {
		this.login_count = login_count;
	}
	
	public int getLoginCount() {
		return login_count;
	}
	
	public String getLastLoginTime() {
		return last_login_time;
	}
	
	public void setLastLoginTime(String login_time) {
		this.last_login_time = login_time;
	}
	
	public static MyInformation parse(InputStream stream) throws IOException, AppException {
		
		MyInformation my_profile = new MyInformation();

		String inputStr;
		BufferedReader streamReader = new BufferedReader( new InputStreamReader(stream) ); 
	    StringBuilder responseStrBuilder = new StringBuilder();
	    while ((inputStr = streamReader.readLine()) != null)
	        responseStrBuilder.append(inputStr);
	    String strResult = responseStrBuilder.toString();
	    
		try {
			
			JSONObject my_profile_json_obj = new JSONObject(strResult);
			
			my_profile.id = my_profile_json_obj.getInt("id");
			my_profile.setEmail(my_profile_json_obj.getString("email"));
			my_profile.setNickName(my_profile_json_obj.getString("nickname"));
			my_profile.setLocation(my_profile_json_obj.getString("location"));
			my_profile.setSummary(my_profile_json_obj.getString("summary"));
			my_profile.setUserAvatar(my_profile_json_obj.getString("avatar_remote"));
			my_profile.setJointime(my_profile_json_obj.getString("create_time"));
			
			my_profile.setFavoritecount( my_profile_json_obj.getInt("favorite_count") );
			my_profile.setFriendCount(my_profile_json_obj.getInt("friends_count"));
			my_profile.setFollowerCount(my_profile_json_obj.getInt("followers_count"));
			
			my_profile.setFBLCount( my_profile_json_obj.getInt("fbl_count") );
			my_profile.setCBLCount(my_profile_json_obj.getInt("cbl_count"));
			my_profile.setPBLCount(my_profile_json_obj.getInt("pbl_count"));

			my_profile.setVoteUpCount(my_profile_json_obj.getInt("vote_up_count"));
			my_profile.setBeVotedCount(my_profile_json_obj.getInt("be_voted_count"));
			
			my_profile.setLoginCount(my_profile_json_obj.getInt("login_count"));
			my_profile.setLastLoginTime(my_profile_json_obj.getString("last_login_time"));
			

		} catch (JSONException e) { 
            System.out.println("Jsons parse error !"); 
            e.printStackTrace(); 
        }
		
	    return my_profile;
	}
}
